package androidchat.com.view;
import java.util.ArrayList;
import java.util.List;

import com.androidchat.R;

import android.content.Context;
import android.net.Uri;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidchat.com.common.FriendEntity;

public class FriendAdapter extends BaseAdapter{
	private Context context;
	private List<FriendEntity> list;
	
	LayoutInflater inflater;
   
	public FriendAdapter(Context context,List<FriendEntity> list){
		this.context = context;
		this.list = list;
		inflater = LayoutInflater.from(context);
	}

	@SuppressWarnings("deprecation")
	public View getView(int position, View convertView, ViewGroup root) {
		convertView = inflater.inflate(R.layout.list_item, null);
		
		ImageView avatar=(ImageView) convertView.findViewById(R.id.ig);
		TextView nick=(TextView) convertView.findViewById(R.id.nick);
		TextView trends=(TextView) convertView.findViewById(R.id.descripetion);
		//avatar.setAlpha(50);
		
		FriendEntity be=list.get(position);
	 int i=context.getResources().getIdentifier(be.getFimage(),"drawable",context.getPackageName());
	 
	    String nickname=be.getFnick();
	    String put_in=FriendFragment.in_put;
	    if(nickname.contains(put_in)){
	    	int index=nickname.indexOf(put_in);
	    	int len=put_in.length();
	    	Spanned temp =Html.fromHtml(nickname.substring(0,index)+ "<u><font color=#FF0000>" + nickname.substring(index, index + len) + "</font></u>"+
	    			 nickname.substring(index +len, nickname.length())) ;
                nick.setText(temp);
	    	
	    	
	    }else{
          nick.setText(be.getFnick());
	    }
	    if(be.getIsonline().equals("0")){
	    	avatar.setAlpha(50);
	    }
		avatar.setImageResource(i);
	
		trends.setText(be.getFdes());
	    
		return convertView;
	    
	}
	public int getCount() {
		int b=0;
		if(list!=null)
		  b=list.size();
		else b=0;
		return b;
		
	}

	public Object getItem(int position) {
		return list.get(position);
	}

	public long getItemId(int position) {
		return position;
	}
}
